import 'package:f200/common/index.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../theme/application/controller/theme_controller.dart';
import '../../application/controller/mine_page_controller.dart';

class MinePageX extends StatelessWidget {
  final controller = Get.find<MinePageController>();
  final themeController = Get.find<ThemeController>();

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Obx(
          () => Container(
            color: Color(0xFFe0dfe0),
            child: Column(
              children: [
                //用户信息，余额
                Container(
                  padding: EdgeInsets.all(8),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [
                        Color(0xFFf44336),
                        Color(0xFFead5c3),
                      ],
                    ),
                  ),
                  child: Column(
                    children: [
                      _buildMemberInfo(),
                      _buildBalance(),
                    ],
                  ),
                ),
                Expanded(
                  child: SingleChildScrollView(
                    padding: EdgeInsets.only(bottom: 20),
                    child: Column(
                      children: [
                        //收藏
                        _buildFavorite(),
                        //订单
                        _buildOrderPanel(),
                        //地址管理等菜单列表
                        _buildMenuList(),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildMemberInfo() {
    var logoutWidget = Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ElevatedButton.icon(
          onPressed: () {
            // Get.toNamed(RouteNames.login);
          },
          icon: Icon(Icons.login),
          label: Text('点击登录'),
          style: ButtonStyle(
            elevation: MaterialStateProperty.all(0),
            backgroundColor:
                MaterialStateColor.resolveWith((states) => Colors.amber),
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(6)),
            color: Colors.deepOrange[200],
          ),
          child: Text('登录享会员特权',
              style: TextStyle(fontSize: 12, color: Colors.grey[800])),
        )
      ],
    );
    var loginWidget = Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('${UserProfileStorage.to.profile.displayName}'),
      ],
    );
    return Row(
      children: [
        SizedBox(
          height: 64,
          child: CircleAvatar(
            backgroundColor: Color(0xFFe3e9df),
            child: Icon(Icons.face_2_outlined, size: 30),
            radius: 30,
          ),
        ),
        SizedBox(width: 8),
        Expanded(
          child: UserProfileStorage.to.isLogin ? loginWidget : logoutWidget,
        ),
        SizedBox(width: 8),
        IconButton(
          splashRadius: 24,
          splashColor: Colors.transparent,
          onPressed: () {
            if (themeController.isDark) {
              themeController.changeThemeMode(ThemeMode.light);
            } else {
              themeController.changeThemeMode(ThemeMode.dark);
            }
          },
          icon: GetBuilder<ThemeController>(builder: (_) {
            return _.isDark
                ? const Icon(Icons.light_mode_outlined)
                : const Icon(Icons.dark_mode_outlined);
          }),
        ),
        SizedBox(width: 8),
        Icon(Icons.qr_code),
        SizedBox(width: 8),
      ],
    );
  }

  Widget _buildBalance() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 4),
              child: Text('0', style: TextStyle(fontWeight: FontWeight.bold)),
            ),
            Text('余额', style: TextStyle(color: Colors.grey[600])),
          ],
        ),
        Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 4),
              child: Text('0', style: TextStyle(fontWeight: FontWeight.bold)),
            ),
            Text('金币', style: TextStyle(color: Colors.grey[600])),
          ],
        ),
        Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 4),
              child: Text('0', style: TextStyle(fontWeight: FontWeight.bold)),
            ),
            Text('积分', style: TextStyle(color: Colors.grey[600])),
          ],
        ),
        Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 4),
              child: Text('0', style: TextStyle(fontWeight: FontWeight.bold)),
            ),
            Text('优惠券', style: TextStyle(color: Colors.grey[600])),
          ],
        )
      ],
    );
  }

  Widget _buildOrderPanel() {
    return Card(
      elevation: 0,
      margin: EdgeInsets.all(4),
      color: Colors.white,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 8.0),
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.fromLTRB(4, 4, 4, 12),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Expanded(child: Text('我的订单')),
                  Text('全部'),
                  Icon(Icons.keyboard_arrow_right,
                      color: Colors.grey, size: 14),
                ],
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Column(
                  children: [
                    Icon(Icons.favorite_border),
                    SizedBox(height: 2),
                    Text('待支付'),
                  ],
                ),
                Column(
                  children: [
                    Icon(Icons.history),
                    SizedBox(height: 2),
                    Text('待发货'),
                  ],
                ),
                Column(
                  children: [
                    Icon(Icons.wallet_membership),
                    SizedBox(height: 2),
                    Text('待收货'),
                  ],
                ),
                Column(
                  children: [
                    Icon(Icons.wallet_membership),
                    SizedBox(height: 2),
                    Text('待评价'),
                  ],
                ),
                Column(
                  children: [
                    Icon(Icons.money),
                    SizedBox(height: 2),
                    Text('退款/售后'),
                  ],
                )
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildFavorite() {
    return Card(
      elevation: 0,
      margin: EdgeInsets.all(4),
      color: Colors.white,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 8.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Column(
              children: [
                Icon(Icons.favorite_border),
                SizedBox(height: 2),
                Text('收藏'),
              ],
            ),
            Column(
              children: [
                Icon(Icons.history),
                SizedBox(height: 2),
                Text('浏览记录'),
              ],
            ),
            Column(
              children: [
                Icon(Icons.wallet_membership),
                SizedBox(height: 2),
                Text('红包卡券'),
              ],
            ),
            Column(
              children: [
                Icon(Icons.money),
                SizedBox(height: 2),
                Text('赚钱'),
              ],
            )
          ],
        ),
      ),
    );
  }

  Widget _buildMenuList() {
    var subtitleStyle = TextStyle(fontSize: 12, color: Coloors.color_B8C0D4);
    return Card(
      elevation: 0,
      margin: EdgeInsets.all(4),
      color: Colors.white,
      child: Padding(
        padding: EdgeInsets.all(6),
        child: Column(
          children: [
            InkWell(
              onTap: () {
                // Get.toNamed(RouteNames.userAddress);
              },
              child: Row(
                children: [
                  Icon(Icons.gps_fixed, size: 16),
                  SizedBox(width: 8, height: 30),
                  Expanded(child: Text('地址管理')),
                  Text('默认收货地址', style: subtitleStyle),
                  Icon(Icons.keyboard_arrow_right,
                      size: 14, color: Colors.grey),
                ],
              ),
            ),
            Divider(indent: 24),
            Row(
              children: [
                Icon(Icons.person, size: 16),
                SizedBox(width: 8, height: 30),
                Expanded(child: Text('个人信息')),
                Text('昵称/头像/性别', style: subtitleStyle),
                Icon(Icons.keyboard_arrow_right, size: 14, color: Colors.grey),
              ],
            ),
            Divider(indent: 24),
            GestureDetector(
              // onTap: () => Get.toNamed(RouteNames.setting),
              child: Row(
                children: [
                  Icon(Icons.settings, size: 16),
                  SizedBox(width: 8, height: 30),
                  Expanded(child: Text('系统设置')),
                  Text('个性化设置', style: subtitleStyle),
                  Icon(Icons.keyboard_arrow_right,
                      size: 14, color: Colors.grey),
                ],
              ),
            ),
            Divider(indent: 24),
            Row(
              children: [
                Icon(Icons.account_circle, size: 16),
                SizedBox(width: 8, height: 30),
                Expanded(child: Text('账号与安全')),
                Text('修改密码/手机号', style: subtitleStyle),
                Icon(Icons.keyboard_arrow_right, size: 14, color: Colors.grey),
              ],
            ),
            Divider(indent: 24),
            Row(
              children: [
                Icon(Icons.help_outline, size: 16),
                SizedBox(width: 8, height: 30),
                Expanded(child: Text('帮助与客服')),
                Text('帮助文档/联系客服', style: subtitleStyle),
                Icon(Icons.keyboard_arrow_right, size: 14, color: Colors.grey),
              ],
            ),
            Divider(indent: 24),
          ],
        ),
      ),
    );
  }
}
